/**
 * Copyright (C), 2015-2019, bogewang
 * FileName: TestSessionController
 * Author:   foren236598164@aliyun.com
 * Date:     2019/9/25 14:54
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bogewang.portal.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 〈〉
 *
 * @author foren236598164@aliyun.com
 * @create 2019/9/25
 * @since 1.0.0
 */
@RestController
@Slf4j
public class TestSessionController {
    @Value("${server.port}")
    private String serverPort;

    // 创建session 会话
    @RequestMapping("/createSession")
    public String createSession(HttpServletRequest request, String nameValue) {
        HttpSession session = request.getSession();
        log.info(">>>>>>>存入Session,SessionId:{},SessionValue:{}", session.getId(), nameValue);
        session.setAttribute("name", nameValue);
        return "success" + ",端口号:" + serverPort;
    }

    // 获取session 会话
    @RequestMapping("/getSession")
    public Object getSession(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        log.info(">>>>>>>获取Session sessionid:{}", session.getId());
        Object value = session.getAttribute("name");
        return value + ",端口号:" + serverPort;
    }
}